package ModelLayer;
import java.util.ArrayList;


/**
 *      AddressBook
 *      Contains an instance of AddressBook(id, name...)
 */
public class AddressBook
{
    // instance variables.
    private ArrayList<Person> p;
    
    public AddressBook()
    {
        p = new ArrayList<Person>();
    }

    public void addPerson(Person p)
    {
        this.p.add(p);
    }
    public Person readPerson(String name)
    {
        Person p = getPerson(name);
        return p;
    }
    public void removePerson(Person p)
    {
        this.p.remove(p);
    }
    public void updatePerson(String name, String address, String postalCode, String city, int phoneNo)
    {
        getPerson(name).updatePerson(name, address, postalCode, city, phoneNo);
    }
    public Person getPerson(String name)
    {
        int index = 0;
        while (p.size()> index)
        {
            Person persons = p.get(index);
            if (persons.getName().contains(name))
            {
                return persons;
            }
            index++;
        }
        return null;
    }
    public ArrayList<Person> listAllPersons()
    {
        return p;
    }
            
        
        
}
